﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TripsLogic.controller;
using System.Data;
using TripsLogic.util;

namespace TripsLogic
{
    public partial class home : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                LoadListTrip();
                
            }
        }
        private void loadLang()
        {
           
        }
    
        private void LoadListTrip()
        {

            //WeSTrip.WeSTripClient client = new WeSTrip.WeSTripClient();

            
            string numberofItem = SysIniController.getSetting("NumberItem_ListTrip", "15");
            DataTable dt = TripController.getNewTrips(Convert.ToInt32(numberofItem));
            if (dt != null && dt.Rows.Count > 0)
            {
                
                string url = "";
                string avatarImagePath = SysIniController.getSetting("Avatar_ImagePath", "images/avatar/");
                string fromLb = LangController.getLng("litFromTitle.Text", "FROM");
                string toLb = LangController.getLng("litToTitle.Text", "TO");
                string driveLb = LangController.getLng("driveBy.Text", "Drive by ");
                string priceLb= LangController.getLng("litPriceTitle.Text", "Price");
                string dateLb = LangController.getLng("litTimeTitle.Text", "Date");
                string currency = LangController.getLng("litCurrency.Text", "DKK");
                string temp = "";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataTable dtUser = SysUserController.getUserById(dt.Rows[i]["SysUserId"].ToString());
                    string userName = dtUser.Rows[0]["LName"].ToString() + " " + dtUser.Rows[0]["FName"].ToString();
                    string avatar= avatarImagePath + dtUser.Rows[0]["Avatar"].ToString();
                    int currentSlot = TripController.getCurrentSlot(Convert.ToInt32(dt.Rows[i]["Id"]));
                    int remainSlot = Convert.ToInt32(dt.Rows[i]["AvaiableSlot"].ToString()) - currentSlot;
                    string slot = "";
                    for (int j = 0; j < currentSlot; j++)
                    {
                        slot = "<img src='images/user00.png' style='height:25px; width:25px'/>" + slot;
                    }

                    for (int j = 0; j < remainSlot; j++)
                    {
                        slot = "<img src='images/user01.png' style='height:25px; width:25px'/>" + slot;

                    }
                    url = "tripinfo "+dt.Rows[i]["AddressFrom"] +" "+ dt.Rows[i]["AddressTo"]+" "+dt.Rows[i]["Id"];
                    url = HTMLRemoval.removeSpecialChar(HTMLRemoval.StripTagsRegex(url)).ToLower().Replace(' ', '-');
                    
                    string[] arrF = dt.Rows[i]["AddressFrom"].ToString().Split(',');
                    string from = "";
                    for (int j = 0; j < arrF.Length - 1; j++)
                    {
                        from = from + arrF[j];
                    }
                    string[] arrT = dt.Rows[i]["AddressTo"].ToString().Split(',');
                    string to = "";
                    for (int j = 0; j < arrT.Length - 1; j++)
                    {
                        to = to + arrT[j];
                    }
                    temp=temp+
                             "<div class='coverItem' >" +
                              "<div class='avatarList'><img src='"+avatar+"' style='height: 90px; width: 90px'></div>" +
                              "<div style='float: left; height: 35px; width: 445px; margin-left: 5px'>" +
                                "<a class='un' href='" + url + "'>" + "<span class='fromto'>" + fromLb + "</span>" + 
                                    "&nbsp;<span style='text-decoration:underline'>" + from + " </span>&nbsp;" +
                                    "<span class='fromto'>" + toLb + "</span>" + "&nbsp;<span style='text-decoration:underline'>" +to + "</span></a>" +
                              "</div>" +

                              "<div class='containtText1'>" +
                                "<div style='float: left'>" + driveLb + "&nbsp;" + userName + "</div>" +
                                "<div style='float: right; display:inline'>" +
                                        slot+
                                "</div>" +
                              "</div>" +
                              "<div class='containtText2'>" +
                                "<span style='float:left'>"+dateLb+"</span>" +
                                "<span style='float:right'>" + priceLb + "&nbsp;" + dt.Rows[i]["Price"] + "&nbsp;"+currency+"</span>" +
                              "</div>" +
                            "</div>";


                   // temp = temp+
                   //"<div style='width: 540px; height: 120px'>" +
                   //     "<div style='float: left; width: 90px; height: 90px'>" +
                   //         "<img src='"+avatar+"' style='height: 90px; width: 90px'>" +
                   //     "</div>" +
                   //     "<div style='float: left; height: 25px; width: 445px; margin-left: 5px'>" +
                   //             "<a href='"+url+"'>"+
                   //                  LangController.getLng("lbFROM.Text", "FROM") + "&nbsp&nbsp" + dt.Rows[i]["AddressFrom"] + 
                   //                  " &nbsp &nbsp" + LangController.getLng("lbTO.Text", "TO") + " " + dt.Rows[i]["AddressTo"] +
                   //             "</a>" +
                   //    "</div>" +
                   //    "<div style='float: right'>" + slot + "</div>" +
                   //    "<div style='float: left; height: 35px; width: 445px; margin-left: 5px; margin-top: 10px'>" +
                   //         userName + 
                   //    "</div>" +
                   //    "<div >Price:" + dt.Rows[i]["Price"] + "</div>" +
                   //    "<div style='float: left; height: 20px; width: 445px; margin-left: 5px;'>" +
                   //    "Date:" + "</div> " +
                   //"</div>";
                }
                litTripList.Text = temp;

            }
        }
    }
}